/**
 * 管理初始化
 */
var Gdhs = {
    id: "GdhsTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Gdhs.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '代码', field: 'gDm', visible: true, align: 'center', valign: 'middle'},
            {title: '名称', field: 'gName', visible: true, align: 'center', valign: 'middle'},
            {title: '所属行业', field: 'gOwerBk', visible: true, align: 'center', valign: 'middle'},
            {title: '增减比例(%)', field: 'gZjbl', visible: true, align: 'center', valign: 'middle'},
            {title: '阳光私募', field: 'gIsYgsmNum', visible: true, align: 'center', valign: 'middle'},
            {title: '个人私募', field: 'gIsGrsmNum', visible: true, align: 'center', valign: 'middle'},
            {title: 'QFILL', field: 'gIsQfillNum', visible: true, align: 'center', valign: 'middle'},
            {title: '基金', field: 'gIsJjNum', visible: true, align: 'center', valign: 'middle'},
            {title: '国家队', field: 'gIsGjdNum', visible: true, align: 'center', valign: 'middle'},
            {title: '企业年金', field: 'gIsQynjNum', visible: true, align: 'center', valign: 'middle'},
            {title: '户数统计截止日', field: 'gTime', visible: true, align: 'center', valign: 'middle'},
            {title: '主力成本', field: 'ZLCB', visible: true, align: 'center', valign: 'middle'},
            {title: '控盘度', field: 'JGCYDType', visible: true, align: 'center', valign: 'middle'},
            {title: '市盈率', field: 'PERation', visible: true, align: 'center', valign: 'middle'},
            {title: '总市值(亿)', field: 'gZsz', visible: true, align: 'center', valign: 'middle'},
            {title: '董监高增减持', field: 'ZJC', visible: true, align: 'center', valign: 'middle'},
            {title: '更新时间', field: 'TDate', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Gdhs.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Gdhs.seItem = selected[0];
        return true;
    }
};

/**
 * 更新
 */
Gdhs.openUpdateGdhs = function () {
	if (this.check()) {
	    var index = layer.open({
	        type: 2,
	        title: '更新股东',
	        area: ['800px', '420px'], //宽高
	        fix: false, //不固定
	        maxmin: true,
	        content: Feng.ctxPath + '/gdhs/gdhs_update_gudong/' + Gdhs.seItem.id
	    });
	    this.layerIndex = index;
	}
};

/**
 * 打开查看详情
 */
Gdhs.openGdhsDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/gdhs/gdhs_update/' + Gdhs.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除
 */
Gdhs.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/gdhs/delete", function (data) {
            Feng.success("删除成功!");
            Gdhs.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("gdhsId",this.seItem.id);
        ajax.start();
    }
};

Gdhs.close = function() {
    parent.layer.close(window.parent.Gdhs.layerIndex);
}

Gdhs.updategudong = function () {
    var ajax = new $ax(Feng.ctxPath + "/gdhs/update_gudong", function (data) {
        Feng.success("更新成功!");
        Gdhs.close()
    }, function (data) {
        Feng.error("更新失败!" + data.responseJSON.message + "!");
    });
    ajax.set("gdhsId",$("#id").val());
    ajax.set("time",$("#time").val());
    ajax.start();
};

Gdhs.formParams = function() {
    var queryData = {};
    queryData['dm'] = $("#dm").val();
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();
    queryData['gtype'] = $("#gtype").val();
    queryData['qfill'] = $("#qfill").val();
    queryData['ygsm'] = $("#ygsm").val();
    queryData['grsm'] = $("#grsm").val();
    queryData['jj'] = $("#jj").val();
    queryData['gjd'] = $("#gjd").val();
    queryData['qynj'] = $("#qynj").val();
    queryData['name'] = $("#name").val();
    queryData['kpd'] = $("#kpd").val();
    queryData['zjc'] = $("#zjc").val();
    return queryData;
}


/**
 * 查询列表
 */
Gdhs.search = function () {
    Gdhs.table.refresh({query: Gdhs.formParams()});
};

$(function () {
    var defaultColunms = Gdhs.initColumn();
    var table = new BSTable(Gdhs.id, "/gdhs/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(Gdhs.formParams());
    Gdhs.table = table.init();
});
